//
//  VoiceRecordLoadingView.m
//  YunShouHu
//
//  Created by WangQiang on 16/6/24.
//  Copyright © 2016年 WangQiang. All rights reserved.
//

#import "VoiceRecordLoadingView.h"
@interface VoiceRecordLoadingView()
@property (weak ,nonatomic) UIImageView *imageView;
@property (weak ,nonatomic) UIImageView *mikeView;
@end
@implementation VoiceRecordLoadingView
-(void)commonInit{
    
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"chatfragment_recording_dialog_rotate_round"];
    imageView.bounds = CGRectMake(0, 0, 150, 150);
    self.imageView = imageView;
    [self addSubview:imageView];
    
    UIImageView *mikeView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"chatfragment_recoding_dialog_icon"]];
    mikeView.bounds = CGRectMake(0, 0, 60, 60);
    self.mikeView = mikeView;
    [self addSubview:mikeView];
    
}
-(instancetype)init{
    if(self = [super init]){
       [self commonInit];
    }
    return self;
}
-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self commonInit];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
//    self.imageView.center = self.center;
    self.imageView.frame = CGRectMake((self.frame.size.width - self.imageView.bounds.size.width)*0.5, (self.frame.size.height - self.imageView.bounds.size.height)*0.5, self.imageView.bounds.size.width, self.imageView.bounds.size.height);
    
    self.mikeView.center = self.imageView.center;
}
-(void)show{
    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
    [window addSubview:self];
    [self startRecordAnimate];
}
-(void)hide{
    [self hideWithCompeletion:NULL];
}
-(void)hideWithCompeletion:(void(^)(BOOL finsh))compeletion{
    [UIView animateWithDuration:0.25 animations:^{
        self.imageView.alpha = 0.0;
        self.mikeView.alpha = 0.0;
    } completion:^(BOOL finished) {
        if(compeletion)compeletion(YES);
        [self removeFromSuperview];
    }];
}
-(void)startRecordAnimate{
//    [self.imageView startLoadingImage];
}
-(void)stopRecordAnimate{
//    [self.imageView endLoadingImage];
}
@end
